{% extends 'layouts/base.html' %}
{% block content %}

<link rel="stylesheet" href="{{config['application']['site']['assetsUri']}}admin/css/AdminLTE.min.css">
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link rel="stylesheet" href="{{config['application']['site']['assetsUri']}}admin/css/morris.css">
<style type="text/css">
    .row-fluid:before,
    .row-fluid:after {
        display: table;
        line-height: 0;
        content: "";
    }
    .row-fluid:after {
        clear: both;
    }
    .row-fluid [class*="span"] {
        display: block;
        float: left;
        width: 100%;
        min-height: 30px;
        margin-left: 2.564102564102564%;
        *margin-left: 2.5109110747408616%;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }
    .row-fluid [class*="span"]:first-child {
        margin-left: 0;
    }
    .row-fluid .controls-row [class*="span"] + [class*="span"] {
        margin-left: 2.564102564102564%;
    }
    .row-fluid .span12 {
        width: 100%;
        *width: 99.94680851063829%;
    }
    .row-fluid .span6 {
        width: 48.717948717948715%;
        *width: 48.664757228587014%;
    }

    .number_input{
        padding: 0px;  
    }
    .row-fluid{
        width:80%;
        margin:0 auto;
    }
</style>
<link rel="stylesheet" href="{{config['application']['site']['assetsUri']}}order/style.css" />
<div class="container" style="width:100%">
    <div class="col-xs-12">
        <div class="box  box-primary">
            <div class="box-header">
                <h3 class="box-title">订单信息</h3>
            </div><!-- /.box-header --> 
            <form  action="{{ url('backend/order/edit') }}" method="post" class="form-horizontal">
                <div class="row-fluid">
                    <div class="help-inline span6">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">订单编号：</label>
                            <label class="help-inline">{{info.order_number}}</label>  
                        </div>
                    </div>
                    <div class="help-inline">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">下单时间：</label>
                            <label class="help-inline">{{info.createtime}}</label>  
                        </div>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="help-inline span6">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">订单状态：</label>
                            <label class="help-inline">
                                {% if info.order_state == 0 %}
                                {% if info.order_place == 1%}
                                未支付
                                {%else%}
                                未确认
                                {%endif%}
                                {%elseif info.order_state == 1%}
                                {% if info.order_place == 1 %}
                                已支付
                                {%else%}
                                已确认
                                {%endif%}
                                {%elseif info.order_state == 2%}
                                已派工
                                {%elseif info.order_state == 3%}
                                完成
                                {%elseif info.order_state == -2%}
                                已退款
                                {%endif%}
                            </label>  
                        </div>
                    </div>
                    <div class="help-inline">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">渠道：</label>
                            <label class="help-inline">
                                {% if info.order_place == 1 %}
                                微信平台
                                {%else%}
                                后台创建
                                {%endif%}
                            </label>  
                        </div>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="help-inline span6">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">搬运日期：</label>
                            <div class="help-inline">
                                <input value='{{info.carrydate}}' id='carrydate' name="carrydate"  type="tel" class="middle-input" {%if info.order_state in [2,3,-2] %} disabled="disabled" {%endif %} >
                            </div>  
                        </div>
                    </div>
                    <div class="help-inline">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">订单类型：</label>
                            <label class="help-inline">
                                {% if info.meal_type == 1 %}
                                套餐
                                {%else%}
                                非套餐
                                {%endif%}
                            </label>  
                        </div>
                    </div>
                </div>     
                <div class="row-fluid">
                    <div class="help-inline span6">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">搬家业务：</label>
                            <div class="help-inline">
                                <select name="carry_type" class="middle-select" {%if info.order_state in [3,-2] %} disabled="disabled" {%endif %} >
                                        {% for v in service %}
                                        <option value="{{v.ser_id}}"  {% if info.carry_type == v.ser_id%}selected="selected" {%endif%}>{{v.ser_name}}</option>
                                    {%endfor%}
                                </select>
                            </div>   
                        </div>
                    </div>
                    <div class="help-inline">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">客户类型：</label>
                            <div class="help-inline">
                                <select class="middle-select" {%if info.order_state == 3 %} disabled="disabled" {%endif %} name="client_type">
                                    <option value="C" {% if info.client_type == 'C' %} selected='selected'{%endif%}>个人</option>
                                    <option value="Q"  {% if info.client_type == 'Q' %} selected='selected'{%endif%}>企业</option>
                                    <option value="Z"  {% if info.client_type == 'Z' %} selected='selected'{%endif%}>政府</option>
                                    <option value="O"  {% if info.client_type == 'O' %} selected='selected'{%endif%}>其他</option>
                                </select>
                            </div>   
                        </div>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="help-inline span6">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">姓名：</label>
                            <div class="help-inline">
                                <input type="text" class="middle-input"  {%if info.order_state in [3,-2] %} disabled="disabled" {%endif %}  name="client_name" value='{{info.client_name}}'>
                            </div>  
                        </div>
                    </div>
                    <div class="help-inline">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">出发地址：</label>
                            <div class="help-inline">
                                <input value='{{info.start_address}}'  name="start_address" type="text" class="middle-input" {%if info.order_state in [3,-2] %} disabled="disabled" {%endif %} >
                            </div>   
                        </div>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="help-inline span6">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">手机：</label>
                            <div class="help-inline">
                                <input value='{{info.client_phone}}'  name="client_phone"  type="tel" class="middle-input" {%if info.order_state in [3,-2] %} disabled="disabled" {%endif %} >
                            </div>  
                        </div>
                    </div>
                    <div class="help-inline">
                        <div class="control-group">
                            <label class="help-inline tip-label-7em">达到地址：</label>
                            <div class="help-inline">
                                <input value='{{info.arrive_address}}'  name="arrive_address"  type="text" class="middle-input"{%if info.order_state in [3,-2] %} disabled="disabled" {%endif %} >
                            </div>   
                        </div>
                    </div>
                </div>       
        </div> 
    </div>
    <div class="col-xs-12">
        <div class="box  box-primary">
            <div class="box-header">
                <h3 class="box-title">费用信息</h3>
            </div><!-- /.box-header -->
            <div class="table-wrap-box">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>项目</th>
                            <th>业务内容</th>
                            <th>价格</th>
                        </tr>
                    </thead> 
                    {% for k,v in info.option_list %}
                    <tr>
                        <td>{{k+1}}</td>
                        <td>{{info.option_list[k]}}</td>
                        {% if info.meal_type == 1%}
                        <td  style="text-align:left;">{{info.content_list[k]|raw}}</td>
                        {% else %}
                        <td>{{info.content_list[k]}}</td>
                        {%endif%}
                        <td>{{info.price_list[k]}}</td>
                    </tr>
                    {% endfor%}
                    <tr>
                        <td></td>
                        <td></td>
                        <td>总价格:</td>
                        <td>{{info.total_price}}</td>
                    </tr>
                </table>
            </div>
        </div>
    </div>    
    <div class="col-xs-12">
        <div class="box  box-primary">
            <div class="box-header">
                <h3 class="box-title">车辆信息</h3>
            </div><!-- /.box-header -->      
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">司机姓名：</label>
                        <div class="help-inline">
                            <input type="text" name="driver_name" value="{{info.driver_name}}" class="middle-input" {%if info.order_state in [0,3,-2] %} disabled="disabled" {%endif %} >
                        </div>  
                    </div>
                </div>
                <div class="help-inline">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">车牌号码：</label>
                        <div class="help-inline">
                            <input name="car_number" value="{{info.car_number}}" placeholder="如：粤A12356" type="text" class="middle-input"  {%if info.order_state in [0,3,-2] %} disabled="disabled" {%endif %}>
                        </div>   
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">司机手机：</label>
                        <div class="help-inline">
                            <input name="driver_phone" value="{{info.driver_phone}}" type="tel" class="middle-input" {%if info.order_state in [0,3,-2] %} disabled="disabled" {%endif %}>
                        </div>  
                    </div>
                </div>
                <div class="help-inline">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">领班人员：</label>
                        <div class="help-inline">
                            <input name="foreman" value="{{info.foreman}}"  type="text" class="middle-input"  {%if info.order_state in [0,3,-2] %} disabled="disabled" {%endif %}>
                        </div>   
                    </div>
                </div>
            </div>
        </div> 
    </div>
    <div class="col-xs-12">    
        <div class="box  box-primary">
            <div class="box-header">
                <h3 class="box-title">金额</h3>
            </div><!-- /.box-header -->      
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">总价格：</label>
                        <label class="help-inline">{{info.total_price}}</label>
                        <label class="help-inline">元</label>    
                    </div>
                </div>
                <div class="help-inline">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">未付款：</label>
                        <label class="help-inline"> {%if info.must_price - info.already_price > 0 %}                       
                            {{info.must_price - info.already_price - info.card_fee}}
                            {%else%}
                            0.00
                            {%endif%}
                        </label>
                        <label class="help-inline">元</label>   
                    </div>
                </div>
            </div>
            <!--        <div class="row-fluid">
                        <div class="help-inline span6">
                            <div class="control-group">
                                <label class="help-inline tip-label-7em">定金比例：</label>
                                <div class="help-inline">
                                    <input id="deposit_rate" type="number" value="{{info.deposit_rate}}" name="deposit_rate" class="smort-input" {%if info.order_state in [1,2,3,] %} disabled="disabled" {%endif %}>
                                </div> 
                                <label class="help-inline">%</label>   
                            </div>
                        </div>
                        <div class="help-inline">
                            <div class="control-group">
                                <label class="help-inline tip-label-7em">定金金额：</label>
                                <label class="help-inline">{{info.deposit_rate_price}}</label>
                                <label class="help-inline">元</label>   
                            </div>
                        </div>
                    </div>-->
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">应付款：</label>
                        <div class="help-inline">
                            <input style="padding:0px; padding-left:5px;" type="number" min="0" name="must_price" value="{{info.must_price}}" class="smort-input number_input"  {%if info.order_state in [1,2,3,-2] %} disabled="disabled" {%endif %}>
                        </div> 
                        <label class="help-inline">元</label>   
                    </div>
                </div>
                <div class="help-inline">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">支付时间：</label>
                        <label class="help-inline">
                            {% if info.already_price_time != empty %}
                            {{info.already_price_time|date("Y-m-d H:i")}}
                            {%else%}
                            00-00-00 00:00
                            {%endif%}
                        </label>  
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">已付款：</label>
                        <label class="help-inline">{{info.already_price}}</label>
                        <label class="help-inline">元</label> 
                        <!--                        <input style="padding:0px; padding-left:5px;" name="already_price" value="{{info.already_price}}" type="number" class="smort-input number_input"  disabled="disabled">
                                            </div> 
                                            <label class="help-inline">元</label>   -->
                    </div>
                </div>
                <div class="help-inline">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">尾款确认时间：</label>
                        <label class="help-inline">
                            {% if info.final_payment_time != null%}
                            {{info.final_payment_time|date("Y-m-d H:i")}}
                            {%else%}
                            00-00-00 00:00
                            {%endif%}
                        </label>  
                    </div>
                </div>
            </div>

            {% if info.card_fee != empty and info.card_title != empty%}
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">优惠券ID：</label>
                        <label class="help-inline">{{info.cardID}}</label>
                    </div>
                </div>
                <div class="help-inline">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">优惠劵卡号：</label>
                        <label class="help-inline">
                            {{info.card_code}}
                        </label>  
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">优惠券名称：</label>
                        <label class="help-inline">{{info.card_title}}</label>
                    </div>
                </div>
                <div class="help-inline">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">优惠劵金额：</label>
                        <label class="help-inline">
                            {{info.card_fee}}
                        </label>  
                    </div>
                </div>          
            </div>
            {%endif%}
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">尾款确认：</label>
                        <div class="help-inline">
                            <input style="padding:0px; padding-left:5px;" min="0" name="final_payment" value="{{info.final_payment}}" type="number" class="smort-input" {%if info.order_state in [0,1,3,-2] %} disabled="disabled" {%endif %}>
                        </div> 
                        <label class="help-inline">元</label>   
                    </div>
                </div>
            </div>
        </div>
    </div> 

    <div class="col-xs-12">
        <div class="box  box-primary">
            <div class="box-header">
                <h3 class="box-title">发票信息</h3>
            </div><!-- /.box-header -->
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">是否开发票：</label>
                        <label class="radio-inline top-place">
                            <input type="radio" name="is_bill" id="Radio1" value="1" {%if info.order_state in [1,2,3,-2] %} disabled="disabled" {%endif %} {% if info.is_bill == 1%} checked="checked"{% endif%} >是
                        </label>
                        <label class="radio-inline top-place">
                            <input type="radio" name="is_bill" id="Radio2" value="0" {%if info.order_state in [1,2,3,-2] %} disabled="disabled" {%endif %} {% if info.is_bill == 0 %} checked="checked"{% endif%}>否
                        </label>
                    </div>
                </div>
                <div class="help-inline">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">发票类型：</label>
                        <label class="help-inline">
                            {%if info.bill_type == 1%}
                                增值税普通发票
                            {%elseif info.bill == 2%}
                                增值税专用发票
                            ｛%else%｝
                                空
                            {%endif%}
                        </label>  
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">抬头：</label>
                        <div class="help-inline">
                            <input value='{{info.bill_title}}' id='carrydate' name="bill_title"  type="tel" class="middle-input" {%if info.order_state in [2,3,-2] %} disabled="disabled" {%endif %} >
                        </div>  
                    </div>
                </div>
                <div class="help-inline ">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">纳税人识别号：</label>
                        <div class="help-inline">
                            <input value='{{info.bill_taxpayer_ID}}' id='carrydate' name="bill_taxpayer_ID"  type="tel" class="middle-input" {%if info.order_state in [2,3,-2] %} disabled="disabled" {%endif %} >
                        </div>  
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">户名：</label>
                        <div class="help-inline">
                            <input value='{{info.bill_account_name}}' id='carrydate' name="bill_account_name"  type="tel" class="middle-input" {%if info.order_state in [2,3,-2] %} disabled="disabled" {%endif %} >
                        </div> 
                    </div>
                </div>
                <div class="help-inline ">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">账号：</label>
                        <div class="help-inline">
                            <input value='{{info.bill_account_number}}' id='carrydate' name="bill_account_number"  type="tel" class="middle-input" {%if info.order_state in [2,3,-2] %} disabled="disabled" {%endif %} >
                        </div> 
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="help-inline span6">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">手机：</label>
                        <div class="help-inline">
                            <input value='{{info.bill_phone}}' id='carrydate' name="bill_phone"  type="tel" class="middle-input" {%if info.order_state in [2,3,-2] %} disabled="disabled" {%endif %} >
                        </div> 
                    </div>
                </div>
                <div class="help-inline ">
                    <div class="control-group">
                        <label class="help-inline tip-label-7em">地址：</label>
                        <div class="help-inline">
                            <input value='{{info.bill_address}}' id='carrydate' name="bill_address"  type="tel" class="middle-input" {%if info.order_state in [2,3,-2] %} disabled="disabled" {%endif %} >
                        </div> 
                    </div>
                </div>
            </div>
            
            <div class="row-fluid">
                <div class="">
                    <div class="control-group">
                        <label class="tip-label-7em help-inline top-place">备注：</label>
                        <div class="help-inline">
                            <textarea name="remark" class="form-control long-textarea" rows="5" placeholder="例如备注特殊物品，具体搬家要求等">{{info.remark}}</textarea>
                            <div class="end-pay-info">
                                <label class="help-inline">应付</label>
                                <label class="help-inline red-label">{{info.must_price}}</label> 
                                <label class="help-inline">元</label>
                                <label class="help-inline">已支付：</label>
                                <label class="help-inline red-label">{{info.already_price}}</label>
                                <label class="help-inline">元</label>
                                <label class="help-inline">尾款：</label>
                                <label class="help-inline red-label">{{info.final_payment}}</label>
                                <label class="help-inline">元</label>
                            </div> 
                        </div>
                    </div>
                </div>
            </div> 
        </div><!-- /.box -->
    </div>

    {% if info.order_state in [0,1,2,3] %}
    <div class="order-btn-box">
        <button  id="submit2" class="btn btn-primary middle-button">保存</button>
        {% if info.order_state in [0,1,2] %}
        <a  class="btn btn-primary little-distance-left middle-button" data-toggle="modal" data-target="#myModal">
            {% if info.order_state == 0 %}
            <td>确认订单</td>
            {%elseif info.order_state == 1%}
            <td>派工</td>
            {%elseif info.order_state == 2%}
            <td>结单</td>
            {%endif%}
        </a>
        {% endif %}
        <a target="_blank" href="{{ url('backend/order/printorder') }}/order_id/{{info.order_id}}" class="btn btn-primary middle-button little-distance-left" >打印订单</a>
    </div>
    {%endif%}
    <input type="hidden" name="order_id" value="{{info.order_id}}">
    </form>
    {% if info.order_state in [0,1,2] %}    
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">
                        {% if info.order_state == 0 %}
                        确认订单
                        {%elseif info.order_state == 1%}
                        派工
                        {%elseif info.order_state == 2%}
                        结单
                        {%endif%}
                    </h4>
                </div>
                <div class="modal-body">
                    是否确认？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="nextState1">确认</button>
                </div>
            </div>
        </div>
    </div>
    {%endif%}    

    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">操作历史</h3>
            </div><!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
                <table class="table table-hover">
                    <tbody><tr>
                            <th>操作者</th>
                            <th>时间</th>
                            <th>订单状态</th>
                            <th>操作内容</th>
                        </tr>
                        {% for v in log%}
                        <tr>
                            <td>{{v.action_user}}</td>
                            <td>{{v.log_time|date('Y-m-d H;i:s')}}</td>
                            <td>
                                {% if v.order_state == 0 %}
                                {% if v.order_place == 1%}
                                <span class="label label-warning">未支付</span>
                                {%else%}
                                <span class="label label-warning">未确认</span>
                                {%endif%}
                                {%elseif v.order_state == 1%}
                                {% if v.order_place == 1 %}
                                <span class="label label-success">已支付</span>
                                {%else%}
                                <span class="label label-success">已确认</span>
                                {%endif%}
                                {%elseif v.order_state == 2%}
                                <span class="label label-warning">已派工</span>
                                {%elseif v.order_state == 3%}
                                <span class="label label-primary">完成</span>
                                {%endif%}                                 
                            </td>
                            <td>{{v.action_note|raw}}</td>
                        </tr>
                        {%endfor%}
                    </tbody></table>
            </div><!-- /.box-body -->
        </div><!-- /.box -->
    </div>
</div>
{% endblock %}
{% block script %}
<script type='text/javascript'>

    $(function () {

        $("#nextState1").unbind().click(function () {
            $("form").attr("action", "{{ url('backend/order/nextstate') }}").submit();
        });
        var check = function () {
            $("input[type='number'']").each(function () {
                var val = $(this).val();
                var result = true;
                var aint = parseInt(val);
                 return aint > 0 && (aint + "") == val;
                 });
        };
        $('#submit2').click(function () {
//            var validate = check();
//            if(validate == false){
//                alert("必须为整数！");
//                return;
//            }
//            return false;
        $("form").submit();
        });
        //日期
        $('#carrydate').datetimepicker({format: 'YYYY-MM-DD HH:mm:ss'}).next().on(ace.click_event, function () {
            $(this).prev().focus();
        });

});

</script>
{% endblock %}
